package com.example.restatr.Atcivity.Traffic;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.restatr.Atcivity.Park.MyCarAt;
import com.example.restatr.R;
import com.example.restatr.Tools;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class TrafficAt extends AppCompatActivity {
    private Toolbar tb;
    private TextView barTitle;
    private EditText search;
    private Banner rbt;
    private GridView card;
    private List<Integer> icons = new ArrayList<>();
    private List<String> titles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_traffic_at );

        tb = findViewById( R.id.toolbar);
        barTitle = findViewById( R.id.bar_Title );
        search = findViewById( R.id.search );
        rbt = findViewById( R.id.banner );
        card = findViewById( R.id.card );

        Tools.SetBarTitle( tb, barTitle, "智慧交管", search, this,false );
        Tools.SetBanner("/prod-api/api/traffic/rotation/list", "","rows","advImg",rbt,this);
        Collections.addAll( icons, R.drawable.ic_________drivinglicence, R.drawable.ic_________illegal, R.drawable.ic_______maintain, R.drawable.ic_______car );
        Collections.addAll( titles, "驾驶证信息", "违章信息", "预约检车", "我的车辆" );
        card.setAdapter( new TrafficAdapter() );
        card.setSelector( new ColorDrawable( Color.TRANSPARENT ) );
    }

    class TrafficAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return icons.size();
        }

        @Override
        public Object getItem(int position) {
            return icons.get( position );
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = getLayoutInflater().inflate( R.layout.traffic_card_item_layout, null );
            ImageView icon = convertView.findViewById( R.id.icon );
            TextView title = convertView.findViewById( R.id.title );
            icon.setImageResource( icons.get( position ) );
            title.setText( titles.get( position ) );
            convertView.setTag( titles.get( position ) );
            convertView.setOnClickListener( new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (v.getTag().toString()) {
                        case "驾驶证信息":
                            startActivity( new Intent( TrafficAt.this, PatenteAt.class ) );
                            break;
                        case "违章信息":
                            break;
                        case "预约检车":
                            startActivity( new Intent( TrafficAt.this, CheckCarPlaceAt.class ) );
                            break;
                        case "我的车辆":
                            startActivity( new Intent( TrafficAt.this, MyCarAt.class ) );
                            break;
                    }
                }
            } );
            return convertView;
        }
    }
}